package com.fdb.efp.console.api.rest.queue;

import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.PubConstant;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.console.service.facade.SRoleDataRuleService;
import com.fdb.efp.console.service.facade.queue.NlsProcessBizHService;
import com.fdb.efp.console.service.vo.queue.NlsProcessBizHVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Controller：网贷业务过程历史
 * 
 * @author huangwb
 * @since 2018年12月27日 上午9:02:22
 * @version 1.0
 */
@RestController
@RequestMapping("/api")
public class NlsProcessBizHController extends AbstractController {

	@Autowired
	@Qualifier("nlsProcessBizHService")
	private NlsProcessBizHService nlsProcessBizHService;

	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;

	/**
	 * 列表数据查询
	 * 
	 * @return
	 */
	@PostMapping(value = "/nls/process/biz/hs")
	public @ResponseBody ResponseData<List<NlsProcessBizHVO>> queryNlsProcessBizHAll(@RequestBody NlsProcessBizHVO vo) {
		// 根据用户角色获取用户权限方案
		List<NlsProcessBizHVO> outputVo = null;
		@SuppressWarnings("unused")
		Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PRD_CODE));
		@SuppressWarnings("unused")
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		setUserInfoToVO(vo);

		// 根据权限方案调用不同的方案进行数据查询
		/** 【不做单独的列表页面，由创建日期来控制数据表的查询  @author qiuyf】
		switch (dataRuleType) {
		case Owner:
			outputVo = nlsProcessBizHService.queryAllOwner(vo);
			break;
		case CurrOrg:
			outputVo = nlsProcessBizHService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = nlsProcessBizHService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = nlsProcessBizHService.queryAllOwner(vo);
			break;
		}*/
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键查询详情
	 * 
	 * @return
	 */
	@GetMapping(value = "/nls/process/biz/h/{applySeq}")
	public @ResponseBody ResponseData<NlsProcessBizHVO> queryByPk(@PathVariable("applySeq") String applySeq) {
		NlsProcessBizHVO inVo = new NlsProcessBizHVO();
		inVo.setApplySeq(applySeq);
		NlsProcessBizHVO outputVo = nlsProcessBizHService.queryByPk(inVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键删除信息
	 * 
	 * @return
	 */
	@DeleteMapping(value = "/nls/process/biz/h")
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody NlsProcessBizHVO inNlsProcessBizHVo) {
		int outputVo = nlsProcessBizHService.deleteByPk(inNlsProcessBizHVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键更新信息
	 * 
	 * @param inNlsProcessBizHVo
	 * @return
	 */
	@PutMapping(value = "/nls/process/biz/h")
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody NlsProcessBizHVO inNlsProcessBizHVo) {
		int outputVo = nlsProcessBizHService.updateByPk(inNlsProcessBizHVo);
		return getResponseData(outputVo);

	}

	/**
	 * 新增数据
	 * 
	 * @param inNlsProcessBizHVo
	 * @return
	 */
	@PostMapping(value = "/nls/process/biz/h")
	public @ResponseBody ResponseData<Integer> insertNlsProcessBizH(@RequestBody NlsProcessBizHVO inNlsProcessBizHVo) {
		int outputVo = nlsProcessBizHService.insertNlsProcessBizH(inNlsProcessBizHVo);
		return getResponseData(outputVo);

	}
}
